-
Notifications
You must be signed in to change notification settings - Fork 5
Display links to things in local systems #1291
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
d866317
to
1f939ce
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! 🙌
We probably want some kind of support for refreshed cache data in the future (so updated libraries data will be reflected in the cache without having to restart the server) but this can maybe be saved for later? I think it would be good to have a comment or issue created regarding this if the question arises.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
See comments.
As discussed offline:
- The key for holders/libraries should be
@id
not sigel - records should be referenced by
@id
, not controlNumber. controlNumber is a MARC identifier and can contain old numeric Libris IDs. If systemIds/fnurgels are preferred because they are shorter in the URL they should be constructed by removing the system base URI prefix.
This behavior hasn't changed in this PR and can be fixed later.
lxl-web/src/lib/utils/holdings.ts
Outdated
export async function getFullHolderData(allHolders: DecoratedHolder[]): Promise<FullHolderBySigel> { | ||
const holderBySigel: FullHolderBySigel = {}; | ||
|
||
for (const h of allHolders) { | ||
const id = h.obj?.['@id']; | ||
const libraryRes = await fetch(`${id}?framed=true`, { | ||
headers: { Accept: 'application/ld+json' } | ||
}); | ||
const resJson = await libraryRes.json(); | ||
const libraryMainEntity = resJson['mainEntity'] as FramedData; | ||
|
||
if (libraryMainEntity) { | ||
holderBySigel[h.sigel] = libraryMainEntity; | ||
} | ||
} | ||
return holderBySigel; | ||
} | ||
|
||
export async function fetchHoldersIfAbsent(holdersByType: HoldersByType) { | ||
const cachedHolders = holdersCache.holders; | ||
const allHolders = Object.values(holdersByType).flat(); | ||
for (const h of allHolders) { | ||
const id = h.obj?.['@id']; | ||
|
||
if (h.sigel && cachedHolders && !cachedHolders[h.sigel]) { | ||
const response = await fetch(`${id}?framed=true`, { | ||
headers: { Accept: 'application/ld+json' } | ||
}); | ||
if (response.ok) { | ||
const resJson = await response.json(); | ||
const libraryMainEntity = resJson['mainEntity'] as FramedData; | ||
if (libraryMainEntity) { | ||
cachedHolders[h.sigel] = libraryMainEntity; | ||
} | ||
} else { | ||
console.error(`Could not fetch holder data for ${id}`); | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could be the same fetch?
error handling missing in the first version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The first function is unused and was probably used before adding the cache+error handling. Must have missed to delete it! Good catch
|
||
const linkTemplateEod = getAtPath(fullHolderData, [BibDb.eodUri], []); | ||
if (linkTemplateEod && linkTemplateEod.length !== 0) { | ||
linksToItem = [linkTemplateEod.replace(/%BIB_*ID%/, bibIdObj.bibId), ...linksToItem]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will only replace the first occurence of %BIB_*ID%
same comment for all replace
</li> | ||
{/if} | ||
{#if linksByBibId[firstBibId]?.[holder.sigel]?.[BibDb.Address]} | ||
{#each linksByBibId[firstBibId][holder.sigel][BibDb.Address] as address (address)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can't use adress
as key here because it's sometimes missing...
Nice work! Apart from comment that breaks the app for me, I mainly have comments regarding the look-and-feel which can be iterated. For example... ![]()
|
Description
Tickets involved
LWS-249
Solves
The goal is to provide access to items in the local library catalog as well as additional library info such as address, opening hours etc. This is currently presented in the holding panel:
Summary of changes